import { defineStore } from 'pinia'
import request from '@/utils/request'
import { apiRes, bannerItem, BrandItem, hotItem, newItem, productItem, specialItem } from '@/types/data'


export default defineStore('home', {
  state: () => ({
    bannerList: [] as bannerItem[],
    newList: [] as newItem[],
    hotList: [] as hotItem[],
    brandList: [] as BrandItem[],
    productList: [] as productItem[],
    specialList: [] as specialItem[]
  }),
  actions: {
    async getBannerList() {
      const res = await request.get<apiRes<bannerItem[]>>('/home/banner')
      this.bannerList = res.data.result
    },
    async getNewList() {
      const res = await request.get<apiRes<newItem[]>>('/home/new')
      // this.bannerList = res.data.result
      this.newList = res.data.result
    },
    async getHotList() {
      const res = await request.get<apiRes<hotItem[]>>('/home/hot')
      // this.bannerList = res.data.result
      // this.hotList = res.data.result
      this.hotList = res.data.result
    },
    async getBrandList() {
      const res = await request.get<apiRes<BrandItem[]>>('/home/brand')
      // this.bannerList = res.data.result
      // this.hotList = res.data.result
      this.brandList = res.data.result
    },
    async getProductList() {
      const res = await request.get<apiRes<productItem[]>>('/home/goods')
      this.productList = res.data.result     
    },
    async getSpecialList() {
      const res = await request.get<apiRes<specialItem[]>>('/home/special')
      this.specialList = res.data.result
    }
  }
})